package com.dcrzl.shcz.module.info.controller;

import java.util.*;

import com.dcrzl.shcz.common.entity.info.Content;
import com.dcrzl.shcz.common.utils.PageInfo;
import com.dcrzl.shcz.common.utils.Result;
import com.dcrzl.shcz.module.info.service.ContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 
 *
 * @author dcrzl
 * @email 1728795786@qq.com
 * @date 2025-01-01 22:49:28
 */
@RestController
@RequestMapping("/content")
public class ContentController {
    @Autowired
    private ContentService contentService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public Result<List<Content>> list(Content content){
       return contentService.selectList(content);
    }

    /**
    * 列表分页
    */
    @GetMapping("/page")
    public PageInfo<Content> page(Content content){
        return contentService.selectUPage(content);
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public Result<Content> info(@PathVariable("id") Long id){
		return contentService.selectById(id);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    public Result<Integer> save(@RequestBody Content content){
        if(Objects.nonNull(content.getReleaseStatus())&&content.getReleaseStatus()==0){
            content.setReleaseTime(new Date());
        }
		return contentService.insert(content);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result<Integer> update(@RequestBody Content content){
		return contentService.updateById(content);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public Result<Integer> delete(@RequestBody Long[] ids){
        return contentService.deleteBatchIds(Arrays.asList(ids));
    }

}
